<template>
  <div>
    <el-dialog
      :title="!dataForm.id ? $t('Common.Add') : $t('Common.Edit')"
      :close-on-click-modal="false"
      :visible.sync="visible"
    >
      <el-form :model="dataForm" ref="dataForm" label-width="auto">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" v-show="dataForm.type === 2" prop="name">
              <el-input :readonly="readonly" v-model="dataForm.name" placeholder="名字"></el-input>
            </el-form-item>
            <el-form-item label="公司名称" v-show="dataForm.type === 1" prop="name">
              <el-input :readonly="readonly" v-model="dataForm.companyName" placeholder="公司名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件类型" v-show="dataForm.type === 2" prop="cardType">
              <el-input :readonly="readonly" v-model="dataForm.cardType" placeholder="证件类型"></el-input>
            </el-form-item>
            <el-form-item label="法人" v-show="dataForm.type === 1" prop="legalPerson">
              <el-input :readonly="readonly" v-model="dataForm.legalPerson" placeholder="法人"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="证件号码" v-show="dataForm.type === 2" prop="idCard">
              <el-input :readonly="readonly" v-model="dataForm.idCard" placeholder="证件号码"></el-input>
            </el-form-item>
            <el-form-item label="统一社会信息码" v-show="dataForm.type === 1" prop="unifiedCode">
              <el-input :readonly="readonly" v-model="dataForm.unifiedCode" placeholder="统一社会信息码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号" prop="linkTel">
              <el-input :readonly="readonly" v-model="dataForm.linkTel" placeholder="手机号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="dataForm.type === 1">
          <el-col :span="12">
            <el-form-item label="公司经营地址" prop="companyAddress">
              <el-input :readonly="readonly" v-model="dataForm.companyAddress" placeholder="公司经营地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人姓名" prop="linkName">
              <el-input :readonly="readonly" v-model="dataForm.linkName" placeholder="联系人姓名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="linkTel">
              <el-input :readonly="readonly" v-model="dataForm.linkEmail" placeholder="linkEmail"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="意向代理城市" prop="proxyCity">
              <el-input :readonly="readonly" v-model="dataForm.proxyCity" placeholder="意向代理城市"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--<el-col :span="12">
            <el-form-item label="所属行业" prop="companyTel">
              <el-select v-model="dataForm.industryInvolved" placeholder="所属行业">
                <el-option
                  v-for="item in industryOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-form-item label="了解招商途径" prop="theWay">
            <el-radio-group v-model="dataForm.theWay">
              <el-radio label="招商大会" name="JoinWay" >招商大会</el-radio>
              <el-radio label="朋友介绍" name="JoinWay" >朋友介绍</el-radio>
              <el-radio label="网络信息" name="JoinWay" >网络信息</el-radio>
              <el-radio label="渠道推荐" name="JoinWay" >渠道推荐</el-radio>
              <el-radio label="其他" name="JoinWay" >其他</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-row>
        <el-row v-show="dataForm.type === 2">
          <el-form-item label="个人情况介绍" prop="companyAddress">
            <quill-editor
              style=" height: 200px;overflow-y: scroll;"
              class="editor"
              v-model="dataForm.introduction"
              ref="myQuillEditor"
              :options="editorOption"
              @blur="onEditorBlur($event)"
              @focus="onEditorFocus($event)"
              @change="onEditorChange($event)"
            ></quill-editor>
          </el-form-item>
        </el-row>
        <el-row v-show="dataForm.type === 1">
          <el-col :span="12">
            <el-form-item label="企业法人" prop="businessProject">
              <el-input :readonly="readonly" v-model="dataForm.legalPerson" placeholder="企业法人"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="统一社会信息码" prop="companyScale">
              <el-input :readonly="readonly" v-model="dataForm.unifiedCode" placeholder="统一社会信息码"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="dataForm.type === 1" >
          <el-col :span="12" >
            <el-form-item label="企业类型" prop="businessProject">
              <el-input :readonly="readonly" v-model="dataForm.companyType" placeholder="企业类型"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="注册资本" prop="companyScale">
              <el-input :readonly="readonly" v-model="dataForm.registeredCapital" placeholder="注册资本"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="dataForm.type === 1">
          <el-col :span="12">
            <el-form-item label="注册地址" prop="businessProject">
              <el-input :readonly="readonly" v-model="dataForm.registeredAddress" placeholder="注册地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="营业期限" prop="companyScale">
              <el-input :readonly="readonly" v-model="dataForm.businessTerm" placeholder="营业期限"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="dataForm.type === 1">
          <el-col :span="12">
            <el-form-item label="主营项目" prop="businessProject">
              <el-input :readonly="readonly" v-model="dataForm.businessProject" placeholder="主营项目"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司规模" prop="companyScale">
              <el-input :readonly="readonly" v-model="dataForm.companyScale" placeholder="公司规模"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="dataForm.type === 1">
          <el-col :span="12">
            <el-form-item label="经营范围" prop="businessProject">
              <el-input :readonly="readonly" v-model="dataForm.businessScope" placeholder="经营范围"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司电话" prop="companyScale">
              <el-input :readonly="readonly" v-model="dataForm.companyTel" placeholder="公司电话"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="预计投入资金" prop="constInput">
              <el-input :readonly="readonly" v-model="dataForm.constInput" placeholder="预计投入资金"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请时间" prop="applyTime">
              <el-input :readonly="readonly" v-model="dataForm.applyTime" placeholder="申请时间"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="身份证照" prop="sfzFront" v-show="dataForm.type === 2">
          <img
            :src="dataForm.sfzFront"
            style="width: 150px;height: 150px;"
            alt=""
            @click="index = 0;showImage = dataForm.sfzFront"
          >
          <img
            v-if="dataForm.sfzBack"
            :src="dataForm.sfzBack"
            style="width: 150px;height: 150px;"
            alt=""
            @click="index = 0;showImage = dataForm.sfzBack"
          >
          <img
            v-if="dataForm.sfzHand"
            :src="dataForm.sfzHand"
            style="width: 150px;height: 150px;"
            alt=""
            @click="index = 0;showImage = dataForm.sfzHand"
          >
          <img
            v-for="item in dataForm.otherImgs.split(',')"
            :src="item"
            style="width: 150px;height: 150px;"
            alt=""
            @click="index = 0;showImage = item"
          >
        </el-form-item>
        <el-form-item label="营业执照" prop="sfzFront" v-show="dataForm.type === 1">
          <img
            :src="dataForm.yyImg"
            style="width: 150px;height: 150px;"
            alt=""
            @click="index = 0;showImage = dataForm.yyImg"
          >
          <img
            v-for="item in dataForm.otherImgs.split(',')"
            :src="item"
            style="width: 150px;height: 150px;"
            alt=""
            @click="index = 0;showImage = item"
          >
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button v-show = "dataForm.state == 1" @click="auditPassHandler(dataForm.id)" type="primary">通过</el-button>
      <el-button v-show = "dataForm.state == 1" @click="auditRefuseHanler(dataForm.id)" type="danger">拒绝</el-button>
    </span>
    </el-dialog>

    <gallery
      :images="[showImage]"
      :index="index"
      @close="index = null"
    />
  </div>
</template>

<script>
import VueGallery from 'vue-gallery';

export default {
  components: {
    'gallery': VueGallery
  },
  data() {
    return {
      readonly:true,
      visible: false,
      dataForm: {
        id: 0,
        userId: "",
        otherImgs:""
      },
      showImage: '',
      index: null
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(
              `/hotel/facilitator/info/${this.dataForm.id}`
            ),
            method: "get",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm = data.facilitators;
              this.dataForm.otherImgs = data.facilitators.otherImgs ? data.facilitators.otherImgs : ""

            }
          });
        }
      });
    },
    //审核通过
    auditPassHandler(id) {
      this.$confirm("确认操作？")
        .then(_ => {
          this.$http({
            url: this.$http.adornUrl(`/hotel/facilitator/auditPass/${id}`),
            method: "POST"
          }).then(({ data: {code, msg }}) => {
            if (code == 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            }else{
              this.$message({
                message: msg,
                type: "error",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            }
          });
        })
        .catch(_ => {});
    },
    auditRefuseHanler(id) {
      this.$confirm("确认操作？")
        .then(_ => {
          this.auditRefuseHanlerMsg(id);
          
        })
        .catch(_ => {});
    },
    
    auditRefuseHanlerMsg(id) {
      this.$prompt('请输入拒绝理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
        inputErrorMessage: '理由不可为空'
      }).then(({ value }) => {
        this.$http({
          url: this.$http.adornUrl(`/hotel/facilitator/auditRefuse/${id}`),
          method: "POST",
          params: this.$http.adornParams({reason:value})
        }).then(({ data }) => {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
       
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
  }
};
</script>
